//
//  MyMoneyViewController.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/2/28.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "MyMoneyViewController.h"

#import "KeHuViewController.h"
#import "JieSuanViewController.h"
#import "DCNavTabBarController.h"

@interface MyMoneyViewController ()<UISearchBarDelegate>
{
    //全局view,好对其删除.
    UIView*view;
    //建两个全局的,来记录你点击了什么
    NSString *one;
    NSString *tow;

}
@property(nonatomic,strong)UISearchBar *moneySeacherBar;
@property(nonatomic,strong)NSMutableDictionary *fangArr;

@end

@implementation MyMoneyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"销售佣金";
    self.view.backgroundColor = BgColor;
    
    _fangArr = [[NSMutableDictionary alloc] init];
       KeHuViewController *keHuVC = [[KeHuViewController alloc] init];
    keHuVC.title = @"客户详情";
    JieSuanViewController *jieVC= [[JieSuanViewController alloc] init];
    jieVC.title = @"结算详情";
    
    NSArray *subViewControllers = @[keHuVC,jieVC];
    
    DCNavTabBarController *tabBarVC = [[DCNavTabBarController alloc]initWithSubViewControllers:subViewControllers];
   
    tabBarVC.view.frame = CGRectMake(0, 108, B_WIDTH, B_HEIGHT - 108);
    [self.view addSubview:tabBarVC.view];
    [self addChildViewController:tabBarVC];

    [self setUpSearchBar];
    
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:self action:@selector(shaiXuanBtnClick:)];
    
    self.navigationItem.rightBarButtonItem = rightBarItem;
    [self.navigationItem.rightBarButtonItem setImage:[[UIImage imageNamed:@"Btn_seacher"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];


    
}

-(void)setUpSearchBar
{
    _moneySeacherBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 64, B_WIDTH, 44)];
    _moneySeacherBar.delegate = self;
    [_moneySeacherBar setPlaceholder:@"请输入搜索内容"];
    [self.view addSubview:_moneySeacherBar];
    
}


#pragma mark- 搜索的方法
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    //第一步注册通知
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center postNotificationName:@"SacherBar" object:searchBar.text userInfo:nil];
}
-(void)shaiXuanBtnClick:(UIButton *)btn
{
 
    //    创建一个View;
    view=[[UIView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 200)];
    view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view];
    
    UILabel *typeLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 8, 100, 20)];
    typeLab.font = [UIFont systemFontOfSize:12];
    typeLab.text = @"回款状态";
    [view addSubview:typeLab];
    
    //线
    for (int i = 0; i<2; i++)
    {
        UILabel *linLab = [[UILabel alloc] init];
        linLab.frame = CGRectMake(0, 62+63*i, B_WIDTH, 0.5);
        linLab.backgroundColor = [UIColor grayColor];
        [view addSubview:linLab];
    }
    NSArray *titArr= @[@"已回款",@"未回款"];
    int AA = (B_WIDTH-20*2-20)/2;
    for (int m = 0; m <2; m++)
    {
        UIButton *chengBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        chengBtn.frame = CGRectMake(20+AA*m, 35, AA-10, 20);
        chengBtn.layer.cornerRadius = 2;
        chengBtn.layer.borderWidth = 1;
        chengBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [chengBtn setTitleColor:[UIColor blackColor] forState:0];
        chengBtn.layer.borderColor = [UIColor grayColor].CGColor;
        chengBtn.tag = 1000+m;
        [chengBtn addTarget:self action:@selector(gouAddBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [chengBtn setTitle:titArr[m] forState:UIControlStateNormal];
        [view addSubview:chengBtn];
        
    }
    
    UILabel *tuiLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, 100, 20)];
    tuiLab.font = [UIFont systemFontOfSize:12];
    tuiLab.text = @"佣金状态";
    [view addSubview:tuiLab];
    
    NSArray *titArr1= @[@"已结清",@"未结清"];
    for (int n = 0; n <2; n++)
    {
        UIButton *tuiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        tuiBtn.frame = CGRectMake(20+AA*n, 95, AA-10, 20);
        tuiBtn.layer.cornerRadius = 2;
        tuiBtn.layer.borderWidth = 1;
        tuiBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [tuiBtn setTitleColor:[UIColor blackColor] forState:0];
        tuiBtn.layer.borderColor = [UIColor grayColor].CGColor;
        tuiBtn.tag = 1002+n;
        [tuiBtn addTarget:self action:@selector(gouAddBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [tuiBtn setTitle:titArr1[n] forState:UIControlStateNormal];
        [view addSubview:tuiBtn];
        
    }
    
    
    //确定按钮
    
    UIButton*determineBtn=[[UIButton alloc]initWithFrame:CGRectMake(10, 145, B_WIDTH-10*2, 35)];
    determineBtn.layer.cornerRadius = 5;
    [determineBtn setTitle:@"确定" forState:UIControlStateNormal];
    [determineBtn addTarget:self action:@selector(determineBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    determineBtn.backgroundColor=[UIColor orangeColor];
    [view addSubview:determineBtn];
    
}
//四个按钮的点击事件,用来记录点击了什么
-(void)gouAddBtnClick:(UIButton*)btn
{
    UIButton*btn1=[self.view viewWithTag:1000];
    UIButton*btn2=[self.view viewWithTag:1001];
    UIButton*btn3=[self.view viewWithTag:1002];
    UIButton*btn4=[self.view viewWithTag:1003];
    
    if (btn.tag==1000) {
        //点击了一排第一个
        one=@"1";
        btn1.backgroundColor=[UIColor orangeColor];
        btn2.backgroundColor=[UIColor whiteColor];
    }else if (btn.tag==1001)
    { //点击了一排第二个
        one= @"2";
        btn2.backgroundColor=[UIColor orangeColor];
        btn1.backgroundColor=[UIColor whiteColor];
        
    }else if (btn.tag==1002)
    { //点击了二排第一个
        tow=@"1";
        btn3.backgroundColor=[UIColor orangeColor];
        btn4.backgroundColor=[UIColor whiteColor];
    }else if (btn.tag==1003)
    { //点击了二排第二个
        tow=@"2";
        btn4.backgroundColor=[UIColor orangeColor];
        btn3.backgroundColor=[UIColor whiteColor];
    }
    
    
}

//确定按钮的点击事件,用来掉接口
-(void)determineBtnClick:(UIButton *)btn
{
    NSLog(@"走这一步了没有%@---%@",one,tow);
    if (one == nil)
    {
         [_fangArr setObject:@"" forKey:@"AA"];
    }
    else if (tow == nil)
    {
      [_fangArr setObject:@"" forKey:@"BB"];
    }
    else
    {
        [_fangArr setObject:one forKey:@"AA"];
        [_fangArr setObject:tow forKey:@"BB"];
    }

   //NSLog(@"%@",_fangArr);
    //点击后直接进行删除view
    [view removeFromSuperview];

    
    //最后让两个int归零,方便下次点击继续记录
    one=@"0" ;
    tow=@"0";
    
    //第一步注册通知
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center postNotificationName:@"cesuo" object:_fangArr userInfo:nil];
}

  


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    }


@end
